<HTML>
<HEAD>
<TITLE>
BeanManager.h
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="green">/*
* Copyright 2006 the original author or authors.
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*      http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/</font>

<font color="blue">#ifndef</font> AUTUMN_BEANMANAGER_H
<font color="blue">#define</font> AUTUMN_BEANMANAGER_H

<font color="blue">#include</font> <font color="maroon">&#60;string&#62;</font>
<font color="blue">#include</font> <font color="maroon">&#60;vector&#62;</font>
<font color="blue">#include</font> <font color="maroon">"Basic.h"</font>
<font color="blue">#include</font> <font color="maroon">"IBeanWrapper.h"</font>
<font color="blue">#include</font> <font color="maroon">"MapHashTable.h"</font>

<font color="blue">using</font> <font color="blue">namespace</font> std;

<font color="blue">namespace</font> Autumn<font color="black">{</font>

<font color="green">/** 
 * Maintains all created beans and dependence relations in them.
 * @version 0.1.0
 * @since 2006-12-9
 */</font>

<font color="blue">class</font> BeanManager<font color="black">{</font>
<font color="blue">private</font><font color="black">:</font>
    <font color="green">/** Divisor for hash table */</font>
    <font color="blue">static</font> <font color="blue">const</font> <font color="blue">int</font> HashDivisor;

    <font color="green">/** All beans */</font>
    MapHashTable<font color="black">&#60;</font>TPointer, TPointer<font color="black">&#62;</font> Beans;
    
    <font color="green">/** Singleton beans */</font>
    map<font color="black">&#60;</font>string, <font color="blue">void</font><font color="black">*</font><font color="black">&#62;</font> SingletonBeans;

    <font color="green">/** Delete a singleton */</font>
    <font color="blue">void</font> deleteSingleton<font color="black">(</font><font color="blue">void</font><font color="black">*</font> p<font color="black">)</font>;
    
<font color="blue">public</font><font color="black">:</font>
    <font color="green">/** Constructor */</font>
    BeanManager<font color="black">(</font><font color="black">)</font><font color="black">:</font>Beans<font color="black">(</font>BeanManager<font color="black">:</font><font color="black">:</font>HashDivisor<font color="black">)</font><font color="black">{</font><font color="black">}</font>

    <font color="green">/** Destructor */</font>
    ~BeanManager<font color="black">(</font><font color="black">)</font>;
    
    <font color="green">/** 
     * Delete a bean from bean manager, but can't delete a singleton truely.
     * A singleton will be deleted at last if it has been created.
     * @param p Pointer to the bean.
     */</font>
    <font color="blue">void</font> deleteBean<font color="black">(</font><font color="blue">void</font><font color="black">*</font> p<font color="black">)</font>;

    <font color="green">/** 
     * Release a bean from bean manager, even if it is a singleton.
     * @param p Pointer to the bean.
     */</font>
    IBeanWrapper<font color="black">*</font> releaseBean<font color="black">(</font><font color="blue">void</font><font color="black">*</font> p<font color="black">)</font>;

    <font color="green">/** 
     * @param p Pointer to the bean.
     */</font>
    IBeanWrapper<font color="black">*</font> getBeanWrapper<font color="black">(</font><font color="blue">void</font><font color="black">*</font> p<font color="black">)</font> <font color="blue">const</font>;

    <font color="green">/** 
     * Add a bean
     * @param name bean's name
     * @param pw Pointer to bean's wrapper
    */</font>
    <font color="blue">void</font> addBean<font color="black">(</font><font color="blue">const</font> string<font color="black">&</font> <font color="blue">name</font>, IBeanWrapper<font color="black">*</font> pw<font color="black">)</font>;

    <font color="green">/** 
     * Find a singleton by name
     */</font>
    <font color="blue">void</font><font color="black">*</font> getSingleton<font color="black">(</font><font color="blue">const</font> string<font color="black">&</font> <font color="blue">name</font><font color="black">)</font><font color="blue">const</font>;
<font color="black">}</font>;

<font color="black">}</font> <font color="green">// End namespace Autumn</font>
<font color="blue">#endif</font>

</PRE>
</BODY>
</HTML>
